package com.byxy.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.byxy.aspect.MyLog;
import com.byxy.entity.Agency;
import com.byxy.entity.Guide;
import com.byxy.entity.Line;
import com.byxy.entity.Order;
import com.byxy.service.OrderService;

public class OrderUpdateAction {

	@Resource
	private OrderService orderService;
	private Integer id;// 序号
	private String title;// 旅游主题
	private int count;// 旅行人数
	private int time;// 旅行花费时间
	private Date startDate;// 开始时间
	private Date endDate;// 结束时间
	private String zt;// 状态
	private String remark;// 备注

	private Order order;

	private Integer agencyId;
	private Integer guideId;
	private Integer lineId;

	private List<Line> lines;
	private List<Agency> agencys;
	private List<Guide> guides;

	@MyLog(desc = "数据更新")
	public String update() {
		if ("POST".equalsIgnoreCase(ServletActionContext.getRequest().getMethod())) {
			Line line = new Line();
			if (lineId == null)
				line = null;
			else
				line.setId(lineId);
			Agency agency = new Agency();
			if (agencyId == null)
				agency = null;
			else
				agency.setId(agencyId);
			Guide guide = new Guide();
			if (guideId == null)
				guide = null;
			else
				guide.setId(guideId);
			Order order = new Order(id, title, count, time, startDate, endDate, zt, line, agency, guide, remark);
			orderService.update(order);
			return "post";
		} else {
			order = orderService.getById(id);
			lines = orderService.findLine();
			agencys = orderService.findAgency();
			guides = orderService.findGuide();
			return "get";
		}
	}

	public Order getOrder() {
		return order;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getZt() {
		return zt;
	}

	public void setZt(String zt) {
		this.zt = zt;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Integer getAgencyId() {
		return agencyId;
	}

	public void setAgencyId(Integer agencyId) {
		this.agencyId = agencyId;
	}

	public Integer getGuideId() {
		return guideId;
	}

	public void setGuideId(Integer guideId) {
		this.guideId = guideId;
	}

	public Integer getLineId() {
		return lineId;
	}

	public void setLineId(Integer lineId) {
		this.lineId = lineId;
	}

	public List<Line> getLines() {
		return lines;
	}

	public void setLines(List<Line> lines) {
		this.lines = lines;
	}

	public List<Agency> getAgencys() {
		return agencys;
	}

	public void setAgencys(List<Agency> agencys) {
		this.agencys = agencys;
	}

	public List<Guide> getGuides() {
		return guides;
	}

	public void setGuides(List<Guide> guides) {
		this.guides = guides;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

}
